#include <iostream>
#include <string>
#include <vector>

int Split(const std::string &str, const std::string &sep, std::vector<std::string> *arry)
{
    int count = 0;
    size_t pos = 0, idx = 0;
    while(true)
    {
        //abc bad def
        //find(要查找的数据， 从哪里开始查找的偏移量);
        pos = str.find(sep, idx);
        if(pos == std::string::npos) break;
        
        if(pos == idx)
        {
            idx = pos + sep.size();
        }
        //substr(截取起始位置，长度); 左闭右开 
        std::string tmp = str.substr(idx, pos - idx);
        arry->push_back(tmp);
        count++;
        idx = pos + sep.size();
    }
    if(idx < str.size())
    {
        arry->push_back(str.substr(idx));
        count++;
    }
    return count; //分割之后数据的个数
}

int main()
{
    std::string str = "abc cde vfr";
    std::vector<std::string> arry;
    Split(str, " ", &arry);
    for(auto &a : arry)
    {
        std::cout << a << std::endl;
    }
    return 0;
}